//
//  CustomTableViewCell.m
//  电影作业
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomTableViewCell.h"
#import "MovieModel.h"

#define kWith self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height

@interface CustomTableViewCell()


@property (nonatomic,retain)UIImageView *movieimageView;
@property (nonatomic,retain)UILabel *namelabel;
@property(nonatomic,retain)UILabel *idlabel;

@end

@implementation CustomTableViewCell
-(void)dealloc
{
    [_cellModel release];
    [_movieimageView release];
    [_namelabel release];
    [_idlabel release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.backgroundColor = [UIColor orangeColor];
        self.namelabel = [[UILabel alloc]init];
        [self.contentView addSubview:_namelabel];
        [_namelabel release];
        
        self.idlabel = [[UILabel alloc]init];
        [self.contentView addSubview:_idlabel];
        [_idlabel release];
        
        self.movieimageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_movieimageView];
        [_movieimageView  release];
        
        
        
       
        
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.movieimageView.frame = CGRectMake(10, 10, kWith * 0.3, kHeight - 20);
    self.movieimageView.backgroundColor = [UIColor redColor];
    
    self.namelabel.frame = CGRectMake(_movieimageView.frame.size.width + 40, 20, kWith * 0.5, kHeight * 0.2);
    
    self.idlabel.frame = CGRectMake(_namelabel.frame.origin.x, kHeight * 0.2 + 40, kWith * 0.5, kHeight * 0.2);
}

-(void)setCellModel:(MovieModel *)cellModel
{
    if (_cellModel != cellModel) {
        [_cellModel release];
        _cellModel = [cellModel retain];
    }
    
    
    NSURL *url = [NSURL URLWithString:cellModel.pic_url];
    
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    UIImage *image = [UIImage imageWithData:data];
    
    self.movieimageView.image = image;
    self.namelabel.text = cellModel.movieName;
    self.idlabel.text = cellModel.movieId;
    
    
}




@end
